Open
Conversation
Author
jasmith-hs
requested changes
Apr 1, 2024
Comment on lines
+144
to
+146
| if (value.matches(".*\\..*,.*")) { | ||
| return value; | ||
| } |
Contributor
There was a problem hiding this comment.
Prefer precompiled regex expressions
Comment on lines
+155
to
+157
| if (!value.matches("\\d*\\.\\d*")) { | ||
| return value; | ||
| } |
Contributor
There was a problem hiding this comment.
Prefer precompiled regex expressions
Comment on lines
+131
to
+134
| if (value instanceof String) { | ||
| String sanitizedValue = trimDecimal(trimCommas((String) value)); | ||
| return super.coerceToByte(sanitizedValue); | ||
| } |
Contributor
There was a problem hiding this comment.
Don't think we should do this when coercing to byte
Comment on lines
+87
to
+90
| assertThat( | ||
| jinjava.renderForResult("{{ \"150.25,0\" is ge 4 }}", new HashMap<>()).getErrors() | ||
| ) | ||
| .isNotEmpty(); |
Contributor
There was a problem hiding this comment.
Some languages have decimals and commas flipped and should be handled in the opposite manner
Author
There was a problem hiding this comment.
Hmm, would your suggested approach here be to make the TruthyTypeConverter constructor take in a JinjavaContext param in order to access in the current language?
Comment on lines
+65
to
+68
| if (value instanceof String) { | ||
| String sanitizedValue = trimCommas((String) value); | ||
| return super.coerceToDouble(sanitizedValue); | ||
| } |
Contributor
There was a problem hiding this comment.
I'd prefer these to use similar logic as in IntFilter and FloatFilter. Make use of NumberFormat#parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
strings can be implicitly coerced to numeric values, so comparisons like:
works. However evaluating:
or:
throws an error. This adds some additional cleaning to allow formatted number strings to be parsed.
Notably it does not remove decimals when comparing to floats, since those are valuable and:
already works.
It also only removes characters after decimals if its a properly formatted decimal number (so containing no non-digit characters and only one decimal point)